<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline"  @keyup.enter.native="searchQuery">
        <a-row :gutter="12">
          <a-col :md="7" :sm="8">
            <a-form-item label="" :labelCol="{span: 6}" :wrapperCol="{span: 14, offset: 0}">
              <a-select
                ref="select"
                v-model="queryParam.brandId"
                placeholder="品牌"
                allowClear
              >
                <a-select-option :value="item.id" v-for="(item, index) in brandOption" :key="index">{{item.brandName}}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="7" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>

      <div class="table-operator" style="border-top: 5px">
        <a-button type="primary" @click="handleAdd">新增</a-button>
      </div>

      <a-table
        ref="table"
        rowKey="id"
        size="middle"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange">
        <!-- <span slot="img" slot-scope="text">
          <img :src="text.split(',')[0]" alt="" class="thumbnail"  style="width:100px;height:100px;"/>
        </span> -->
        <span slot="status" slot-scope="text, record">
          <a-switch :checked="record.status == 0" @click="handleSwitch(record,$event ? ischoose : noChoose)"></a-switch>  {{record.statusText}}
        </span>
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">
            <a-icon type="edit"/>
            编辑
          </a>
          <a-divider type="vertical"/>
          <a-popconfirm title="确定删除吗?" @confirm="() =>handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span>
      </a-table>
    </div>

    <rule-Modal ref="modalForm" @ok="modalFormOk"></rule-Modal> 
  </a-card>
</template>

<script>
import { filterObj } from '@/utils/util';
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ruleModal from './modules/ruleModal'
import { brandList, saveOrUpdateRule } from '@/api/marketingCenter/newmember.js'

export default {
  name:'',
  mixins:[JeecgListMixin],
  components: { 
    ruleModal
  },
  data() {
    return {
      ischoose: 0,
      noChoose: 1,
      removeVisible: false,
      qrCode:'',
      queryParam:{
        current: 1,
        size: 10,
      },
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 120,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        // {
        //   title: '图片',
        //   dataIndex: 'images',
        //   align: 'center',
        //   scopedSlots: { customRender: 'img' }
        // },
        {
          title: '品牌',
          align: "center",
          dataIndex: 'brandText',
        },
        {
          title: '位置',
          align: 'center',
          dataIndex: 'typeText',
        },
        {
          title: '备注',
          align: 'center',
          dataIndex: 'remark',
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'status',
          scopedSlots: { customRender: 'status' }
        },
        {
          title: '操作',
          align: "center",
          dataIndex: 'action',
          scopedSlots: {customRender: 'action'},
        }
      ],
      url: {
        list: "/backend/vip/invite/pageRuleVo",
        delete: "/backend/vip/invite/delRuleById",
      },
      status:"启用",
      brandOption:[],
    }
  },
  created() {
    this.getbrandList()
  },
  methods: {
    getQueryParams() {
      var param = Object.assign({}, this.queryParam);
      param.current = this.ipagination.current;
      param.size = this.ipagination.pageSize;
      return filterObj(param);
    },
    getbrandList() {
      brandList().then(res => {
        if (res.code == 200) {
          this.brandOption = res.data
        }
      })
    },
    handleSwitch(record,cover) {
      console.log(record,cover);
      saveOrUpdateRule({
        'id':record.id,
        'status':cover,
        'brandId':record.brandId, 
        'type':record.type, 
        'images':record.images 
        }).then(res => {
          if (res.code == 200) {
            this.$message.success(res.msg)
            this.loadData(1)
          } if (res.code == 500) {
            this.$message.warning(res.msg)
          }
      })
    },
  }
}
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>